package zozopo.warehouse;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.background.operator.operations.OperatorTB;
import zozopo.background.operator.operations.OperatorlimitedTB;
import zozopo.database.BusiDatabaseManager;
import zozopo.database.DatabaseManager;
import zozopo.user.operations.UserOS;
import zozopo.user.operations.UserTB;
import zozopo.warehouse.operations.BackreceiptlistOS;
import zozopo.warehouse.operations.BackreceiptlistTB;
import zozopo.warehouse.operations.PurchaseOS;
import zozopo.warehouse.operations.PurchaseTB;


import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class InfoBackreceiptlistAction extends ActionSupport implements Action,SessionAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final String limitedCode ="WAREHOUSE.BACKRECEIPTLIST";
	
	//传入参数
	private int id;
	
	//传出参数
	private String operationResult;
	private BackreceiptlistTB backreceiptlist;
	private List<PurchaseTB> list;
	
	
	private Map<Object, Object> session;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	public String execute(){
		
		
	
		DatabaseManager databaseManager = new BusiDatabaseManager();
		Connection conn = databaseManager.getConnection();
		
		BackreceiptlistOS backreceiptlistOS = new BackreceiptlistOS(conn);
		PurchaseOS purchaseOS = new PurchaseOS(conn);
		
	
		backreceiptlist = backreceiptlistOS.get(id);
		list = purchaseOS.getListByBackreceiptlistId(id);
				
		databaseManager.releaseConnection(conn);
		
		return SUCCESS;
	}
	
	public void validate() {
		//权限处理
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		
		//用户权限
		Map<String,OperatorlimitedTB> operatorlimitedMap = (Map<String,OperatorlimitedTB>)session.get("operatorlimitedMap");
		
		if(operatorlimitedMap.get(limitedCode) == null){
			addFieldError("errormessage","用户未有查看退货权限.");
			return;
		}
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getOperationResult() {
		return operationResult;
	}
	public void setOperationResult(String operationResult) {
		this.operationResult = operationResult;
	}
	
	public List<PurchaseTB> getList() {
		return list;
	}
	public void setList(List<PurchaseTB> list) {
		this.list = list;
	}
	public BackreceiptlistTB getBackreceiptlist() {
		return backreceiptlist;
	}
	public void setBackreceiptlist(BackreceiptlistTB backreceiptlist) {
		this.backreceiptlist = backreceiptlist;
	}
	public static String getLimitedcode() {
		return limitedCode;
	}

}
